﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE80;
using EnvDTE;
using System.Windows.Forms;

namespace eVision.SharpSort.VSAddIn
{
    public class LayoutInformation
    {
        public LayoutInformation(Connect connect, String layoutName, String path)
        {
            this.Application = connect.Application;
            this.CommandName = connect.LayoutsStartPrefix + layoutName;
            this.LayoutName = layoutName;
            this.Path = path;
        }

        public Command Command { get; set; }
        public DTE2 Application { get; private set;}
        public String Path { get; set; }
        public String LayoutName { get; set; }
        public bool Exist { get; set; }
        public String CommandName { get; private set; }

        public void ExecuteResharp(bool eraseNotSpecifiedElements)
        {
            try
            {
                SharpSort.CodeFormatter.FormatCode(Application.ActiveDocument, Path, eraseNotSpecifiedElements);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " : " + ex.StackTrace);

                if (ex.InnerException != null)
                    MessageBox.Show(ex.InnerException.Message + " :" + ex.InnerException.StackTrace);
            }
        }

        public vsCommandStatus StatusResharp()
        {
            if (Application.ActiveDocument.Language == "CSharp")
            {
                return vsCommandStatus.vsCommandStatusEnabled | vsCommandStatus.vsCommandStatusSupported;
            }
            else
            {
                return vsCommandStatus.vsCommandStatusUnsupported;
            }
        }
    }
}
